//
//  LYQMineNewAlertsViewController.m
//  ZCProject
//
//  Created by Zheng on 16/11/18.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQMineNewAlertsViewController.h"

#import "LYQMineNewAlertCell.h"

#define kLYQMineNewAlertCell_ID @"kLYQMineNewAlertCell_ID"

@interface LYQMineNewAlertsViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *titleNamesArr;

@end

@implementation LYQMineNewAlertsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"新消息通知";
    
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    self.listTableView.scrollEnabled = NO;
    [self.listTableView registerClass:[LYQMineNewAlertCell class] forCellReuseIdentifier:kLYQMineNewAlertCell_ID];
    
    _titleNamesArr = @[@"接收新消息通知",@"声音",@"震动"];
}


#pragma mark - tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    } else {
        return 2;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LYQMineNewAlertCell *cell = [tableView dequeueReusableCellWithIdentifier:kLYQMineNewAlertCell_ID forIndexPath:indexPath];
    
    if (indexPath.section == 0) {
        cell.statusSwitch.hidden = YES;
    } else {
        cell.alertStatusLbl.hidden = YES;
        
        if (indexPath.row == 0) {
            cell.statusSwitch.on = YES;
        }
    }
    
    cell.textLabel.text = _titleNamesArr[indexPath.row+indexPath.section];
    
    return cell;
}

#pragma mark - tableview delegate
#pragma mark 头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return kWScale(10.5);
    } else {
        return kWScale(55);
    }
}

#pragma mark 单元格高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kWScale(50);
}

#pragma mark 尾视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001f;
}

#pragma mark 自定义头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return nil;
    } else {
        
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kMS_Width, kWScale(55))];
        
        UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(kWScale(15), 0, kMS_Width-kWScale(30), kWScale(55))];
        titleLbl.text = @"如果您要关闭或开启旅业圈的新消息推送通知,请在手机\n的 \"设置\"  \"通知\" 功能中, 找到 \"旅业圈\" 更改";
        titleLbl.font = kWFont(13);
        titleLbl.textColor = kHexadecimal(@"666666");
        titleLbl.numberOfLines = 2;
        
        [headerView addSubview:titleLbl];
        
        return headerView;
    }
}

#pragma mark 设置分割线偏移量
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, kWScale(10), 0, 0)];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, kWScale(10), 0, 0)];
    }
}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
